#ifndef __WORKQ_H_
#define __WORKQ_H_

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <queue>
#include "Task.h"
#include <stdio.h>
//#include <libgtop-2.0/glibtop.h>
//#include <libgtop-2.0/glibtop/proclist.h>
//#include <libgtop-2.0/glibtop/cpu.h>
//#include <glib-2.0/glib.h>
#include <vector>
#include <dbitvec.h>

class WorkQueue {
 private:
  int num_threads;
  std::queue<Task*> workq;
  std::vector < pthread_t *> pool;
  dbitvec enabled;
  //pthread_t* pool;  
  pthread_cond_t empty_cond;
  pthread_mutex_t cmutex;
  pthread_mutex_t qmutex;
  int count;
  pthread_cond_t done;
  pthread_t monitor;
  friend void* run_thread(void*); // the function that the thread implements //

  /**
   * \brief friend function for intelligence monitor
   */
  friend void* run_monitor(void*);

 public:
  WorkQueue ();
  
  ~WorkQueue () {
      wait_for_threads();
  }

  void setNumThreads(int number); // set the number of threads in the pool //

  int initThreads(); // initialize the threads in the pool //

  int addTask(Task* t); // add a new task to the queue //

  int wait_for_threads(); // wait for the threads to come back //

};

void wait_for_task(Task* t);

struct thread_args {
    WorkQueue * _Q;
    dbitvec * _visited;
    int id;
};
#endif
